const qiniu = require('qiniu')

var accessKey = '03FNGagRAsv4Aga41uLWSTqi8aRSt5YKaoJg2vdz';
var secretKey = 'zfY4ECP2OwcMSEqz515t4M7K3TXmyHm65HRrxSLA';
var mac = new qiniu.auth.digest.Mac(accessKey, secretKey);


var options = {
    scope: "koaone",
    returnBody: '{"key":"$(key)","hash":"$(etag)","fsize":$(fsize),"bucket":"$(bucket)","name":"$(x:name)"}'
};
var putPolicy = new qiniu.rs.PutPolicy(options);
var uploadToken = putPolicy.uploadToken(mac);

var config = new qiniu.conf.Config();
// 空间对应的机房
config.zone = qiniu.zone.Zone_z2;

var localFile = "./images/game_bg.jpg";
var formUploader = new qiniu.form_up.FormUploader(config);
var putExtra = new qiniu.form_up.PutExtra();
var key = 'test.jpg';
// 文件上传
formUploader.putFile(uploadToken, key, localFile, putExtra, function(respErr,
    respBody, respInfo) {
    if (respErr) {
        throw respErr;
    }
    if (respInfo.statusCode == 200) {
        console.log(respBody);
    } else {
        console.log(respInfo.statusCode);
        console.log(respBody);
    }
});